package com.chatsimple.netty.task

import com.chatsimple.logDebug
import com.google.protobuf.ByteString
import com.ly.data.MessageProtobuf
import io.netty.channel.Channel

class ChatHandler : ITaskHandler {

    override fun handle(channel: Channel, task: MessageProtobuf.TaskProto) {
        if (task.type != MessageProtobuf.TaskType.Chat) return
        //理论上，这里找到对应的receiverId发送成功，再给sender应答
        //这里简单直接应答
        channel.writeAndFlush(
            task.toBuilder()
                .setData(ByteString.EMPTY)
                .build()
        ).addListener {
            logDebug("ChatTask 应答结果:${it.isSuccess}")
        }
    }

    override fun destroy(channel: Channel?) {

    }
}